﻿using Microsoft.Data.SqlClient;
using System.Data;

namespace Dz.WorkerService.Utils
{
    
    internal class CustUtils : BaseUtils
    {
        private List<string> custs = new List<string>();
        private static readonly Lazy<CustUtils> instance = new Lazy<CustUtils>(() => new CustUtils());

        public static CustUtils Instance => instance.Value;

        protected override void Init()
        {
            string sql = @"select a.code + '/' + b.code 
                        from CBO_customer a
                        inner join Base_Organization b on a.org = b.ID";

            DataTable dt = sqlUtils.FillSync(sql);

            foreach (DataRow dr in dt.Rows) 
            {
                custs.Add(dr[0].ToString());
            }
        }

        public bool IsExists(string cust, string org)
        {
            return custs.Contains($"{cust}/{org}");
        }
        public override void ReLoad()
        {
            custs.Clear();
            Init();
        }

    }
}
